package java6699.lesson12;


import java.util.*;


public class CourseStream6699 {
    public static void main(String[] args) {
        System.out.println("======85分以上的课程名单======");
        System.out.println("共" + getCourses().stream()
                .filter(n -> n.getScore() >= 85)
                .count() + "门");//统计85分以上共几门
        getCourses().stream().filter(n -> n.getScore() >= 85)
                .forEach(System.out::println);//将85分以上的课程输出
        OptionalDouble avg = getCourses().stream()
                .mapToInt(Course6699::getScore).average();//求平均分
        System.out.print("【1】所有课程的平均分：");
        System.out.println(avg.isPresent()?avg.getAsDouble():"没有课程");
        System.out.println("【2】最高分的课程：");
        Optional<Course6699> max = getCourses().stream()
                .max(Comparator.comparing(Course6699::getScore));
        System.out.println(max.isPresent()?max.get():"没有课程");
        System.out.println("【3】最低分的课程：");
        Optional<Course6699> min = getCourses().stream()
                .min(Comparator.comparing(Course6699::getScore));
        System.out.println(min.isPresent()?min.get():"没有课程");
    }

    private static List<Course6699> getCourses() {
        List<Course6699> courses = new ArrayList<Course6699>();
        courses.add(new Course6699("A001", "C程序设计基础", "1上", 4, 80));
        courses.add(new Course6699("A004", "离散数学", "1下", 3, 79));
        courses.add(new Course6699("B002", "Pthon程序基础", "1下", 2, 85));
        courses.add(new Course6699("A002", "面向对象程序设计", "2上", 3, 78));
        courses.add(new Course6699("C012", "软件测试", "3下", 2, 72));
        courses.add(new Course6699("C001", "Java程序高级开发", "3上", 2, 83));
        courses.add(new Course6699("0003", "大学物理", "2上", 2, 77));
        courses.add(new Course6699("C002", "软件工程", "3下", 3, 75));
        courses.add(new Course6699("C011", "移动项目开发", "3下", 2, 87));
        courses.add(new Course6699("B001", "操作系统", "2下", 3, 90));
        courses.add(new Course6699("A005", "算法与数据结构", "2上", 3, 82));
        courses.add(new Course6699("A003", "数据库原理", "2上", 3, 78));
        courses.add(new Course6699("C003", "前端开发技术", "3上", 3, 69));
        courses.add(new Course6699("B003", "网络基础", "2下", 3, 75));
        courses.add(new Course6699("0001", "大学英语", "1上", 3, 80));
        courses.add(new Course6699("0002", "高等数学", "1下", 2, 85));
        courses.add(new Course6699("B004", "计算机网络", "1下", 4, 68));
        courses.add(new Course6699("B005", "计算机数组原理", "2上", 4, 78));
        return courses;
    }

    private static class Course6699 {
        private String no;//课程编号
        private String name;//课程名称
        private String term;//开课学期
        private int credit;//学分
        private int score;//成绩

        @Override
        public String toString() {
            return String.format("%s %-8s\t\t%s,%d,%d", this.no,this.name,this.term,this.credit,this.score);

        }

        public Course6699() {
            super();
        }

        public Course6699(String no, String name, String term, int credit, int score) {
            super();
            this.no = no;
            this.name = name;
            this.term = term;
            this.credit = credit;
            this.score = score;
        }

        public String getNo() {
            return no;
        }

        public void setNo(String no) {
            this.no = no;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getTerm() {
            return term;
        }

        public void setTerm(String term) {
            this.term = term;
        }

        public int getCredit() {
            return credit;
        }

        public void setCredit(int credit) {
            this.credit = credit;
        }

        public int getScore() {
            return score;
        }

        public void setScore(int score) {
            this.score = score;
        }

    }

}
